<template>
  <div>
    <!-- <TopBavBar></TopBavBar> -->
    <div class="home-banner">
      <div class="banner-container">
        <!-- 联系方式 -->
        <h1 class="blog-title animated zoomIn">忘月</h1>
        <!-- 一言 -->
        <div class="blog-intro">可以失去 不可放弃</div>
      </div>
      <div class="scroll-down" @click="scrollDown">
        <div class="scroll-down-effects">
          <i class="el-icon-arrow-down"></i>
        </div>
      </div>
    </div>
    <!-- 主页文章 -->
    <div class="container">
      <div class="swiper">
        <swiper></swiper>
      </div>
      <div class="cont_banner_box">
        <ul class="con_banner" v-for="essay in essayList" :key="essay.id">
          <li>
            <a href="">
              <img :src="essay.image" alt="" />
              <section>
                <router-link :to="{ path: `/essay` }">
                  <span :style="{ background: essay.color }">生活随笔</span>
                </router-link>
                <router-link :to="{ path: `/essaycon/${essay.id}` }">
                  <p>{{ essay.title }}</p>
                </router-link>
              </section>
            </a>
          </li>
        </ul>
      </div>
      <div class="home-container">
        <el-row :gutter="20">
          <el-col :span="17" :xs="24" :sm="17">
            <div class="article-card">
              <ul v-for="blog in blogList" :key="blog.id">
                <li class="art_list">
                  <div class="art_header">
                    <div class="art_title">
                      <div style="display: flex; align-items: center">
                        <router-link :to="{ path: `/article/${blog.id}` }">
                          <h2>{{ blog.title }}</h2>
                        </router-link>
                        <i
                          class="iconfont iconzhiding"
                          style="color: red; margin-left: 15px"
                        />
                        {{ blog.flag }}
                      </div>

                      <span>作者：|忘月</span>
                      <span>分类：|{{ blog.blog_type }}</span>
                    </div>
                    <div class="blog-head-time">
                      <div class="blog-head-time-day">
                        {{ blog.create_time | dateFormatFilter("DD") }}
                      </div>
                      <div class="blog-head-time-date">
                        <div class="blog-head-time-date-month">
                          {{ blog.create_time | dateFormatFilter("MM") }}月
                        </div>
                        <div class="blog-head-time-date-year">
                          {{ blog.create_time | dateFormatFilter("YYYY") }}
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="art_content">
                    <img :src="blog.first_picture" alt="" />

                    <span>
                      {{ blog.content }}
                    </span>
                  </div>
                </li>
              </ul>
            </div>
          </el-col>
          <el-col :span="7" :xs="24" :sm="7">
            <div class="mycard">
              <section>
                <div class="mycard_title">
                  <div class="avatar">
                    <img
                      class="author-avatar"
                      src="@/assets/image/avatar.jpg"
                    />
                  </div>
                  <div class="my">
                    <p class="mycard_nickname">忘月</p>
                  </div>
                  <p class="mycard_en">是微风，是晚霞，是心跳，是无可替代</p>
                </div>

                <i>
                  <img src="@/assets/image/ff.jpg" alt="" />
                </i>
              </section>
            </div>
            <div class="tagsclous">
              <h2 class="h_title">标签云</h2>
              <ul>
                <li href="" v-for="item in typeList" :key="item.id">
                  {{ item.name }}
                </li>
              </ul>
            </div>
            <div class="rilr">
              <rili></rili>
            </div>
          </el-col>
        </el-row>

        <!-- <el-pagination
            background
            layout="total, prev, pager, next"
            :total="totalcount"
          >
          </el-pagination> -->

        <!-- <el-card>
          <div id="he-plugin-standard" class="weather"></div>
        </el-card> -->
      </div>
    </div>
  </div>
</template>
<script>
import { getblogs, getEssay, getType } from "@/request/api";
// import TopBavBar from "@/components/common/TopNavBar.vue";
import Swiper from "@/components/common/Swiper.vue";
import Rili from "@/components/common/rili.vue";
export default {
  name: "home",
  components: { Swiper, Rili },
  props: [""],

  computed: {
    pagSmall() {
      return this.screenWidth <= 768;
    },
    // 计算分页栏样式
    pagLayout() {
      if (this.screenWidth < 768) {
        return "prev, pager, next";
      } else {
        return "total, prev, pager, next, jumper";
      }
    },
  },
  data() {
    return {
      totalcount: 100,
      queryInfo: {
        title: "",
        typeId: "",
      },
      year: "",
      month: "",
      day: "",
      pagenum: 1,
      pagesize: 4,
      blogList: [],
      typeList: [],
      tagList: [],
      recommendList: [],
      essayList: [],
    };
  },
  created() {
    // this.initWeather();
    this.getBlogList();
    this.getEssay();
    this.getType();
  },
  mounted() {},
  methods: {
    scrollDown() {
      // let el = document.getElementsByClassName(".home-container");
      window.scrollTo({
        behavior: "smooth",
        top: document.documentElement.clientHeight,
      });
    },

    initWeather() {
      window.WIDGET = {
        CONFIG: {
          layout: "1",
          width: 350,
          height: 300,
          background: "2",
          dataColor: "000000",
          borderRadius: "5",
          key: "4034255d0cc94897b5f745367ccb81f2",
        },
      };
      let script = document.createElement("script");
      script.type = "text/javascript";
      script.src =
        "https://widget.qweather.net/standard/static/js/he-standard-common.js?v=2.0";
      document.getElementsByTagName("head")[0].appendChild(script);
    },
    // changeWeatherWidth() {
    //   this.timer = setInterval(() => {
    //     const weatherDom = document.getElementById("he-plugin-standard");
    //     const domW = getComputedStyle(weatherDom, false).width;
    //     if (domW === "2px") {
    //       weatherDom.style.width = "100%";
    //       clearInterval(this.timer);
    //     }
    //   }, 100);
    // },

    // 获取博客列表
    async getBlogList() {
      const { data: res } = await getblogs({
        query: this.queryInfo.title,
        typeId: this.queryInfo.typeId,
        pagenum: this.pagenum,
        pagesize: this.pagesize,
      });

      this.blogList = res.data.slice(0, 4);
      this.totalcount = res.total;
    },
    async getType() {
      const { data: res } = await getType();
      this.typeList = res.data;
    },
    async getEssay() {
      const { data: res } = await getEssay({
        pagenum: this.pagenum,
        pagesize: this.pagesize,
      });

      this.essayList = res.data.slice(0, 4);
      // this.totalcount = res.total;
    },

    // 修改当前页码
    handleCurrentChange(newSize) {
      this.pagenum = newSize;
      this.getBlogList();
    },
    // 修改当前页大小
    handleSizeChange(newSize) {
      this.pagesize = newSize;
    },
  },
};
</script>
<style scoped>
.home-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  background-attachment: fixed;
  background: url("山.jpg") no-repeat;
  background-size: 100% 100%;
  text-align: center;
  color: #fff !important;
  animation: header-effect 1s;
}
.banner-container {
  margin-top: 55vh;
  margin-left: -25vw;
  line-height: 1.5;
  color: rgb(251, 242, 242);
}
.blog-title {
  font-size: 2.5rem;
}

.blog-intro {
  font-size: 1.5rem;
}
.scroll-down {
  cursor: pointer;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 60px;
}

.scroll-down i {
  font-size: 2rem;
}
.scroll-down-effects {
  color: #eee !important;
  text-align: center;
  text-shadow: 0.1rem 0.1rem 0.2rem rgba(0, 0, 0, 0.15);
  line-height: 1.5;
  display: inline-block;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  animation: scroll-down-effect 1.5s infinite;
}

.swiper {
  width: 100%;
  height: 350px;
  box-shadow: 0 0 3pc rgba(0, 0, 0, 0.4);
  border-radius: 10px;
}
.cont_banner_box {
  padding-top: 10px;
  width: 100%;
  margin: 25px auto;
}

.con_banner li {
  font-size: 18px;
  float: left;
  width: 25%;
}
.con_banner li a {
  position: relative;
  display: block;
  border-radius: 5px;
  margin: 0 10px;
  overflow: hidden;
}
.con_banner img {
  height: 200px;
  width: 100%;
  transition: all 0.5s;
}
.con_banner li a section {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0;
  color: #fff;
  z-index: 9;
  text-align: left;
  padding: 20px 0;
}
.con_banner li section span {
  margin: 0 20px;
  padding: 5px 10px;
  background: #ff3a3a;
  color: #fff;
  border-radius: 3px;
  font-size: 14px;
  line-height: 26px;
}
.con_banner li a section p {
  padding: 0 20px 0 0px;
  margin: 20px 0 0 20px;

  line-height: 26px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #fff;
}
.article-card {
  margin-top: 25px;
}
@keyframes scroll-down-effect {
  0% {
    top: 0;
    opacity: 0.4;
    filter: alpha(opacity=40);
  }
  50% {
    top: -16px;
    opacity: 1;
    filter: none;
  }
  100% {
    top: 0;
    opacity: 0.4;
    filter: alpha(opacity=40);
  }
}
@keyframes header-effect {
  0% {
    opacity: 0;
    filter: alpha(opacity=0);
    transform: translateY(-50px);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: translateY(0);
  }
}
.container {
  margin: calc(100vh + 10px) auto 28px auto;
  max-width: 1200px;
  padding: 0px 5px;
}
.home-container {
  margin-top: 20px;
  width: 100%;
  transform: none;
  overflow: hidden;
}

.art_header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: rgb(113, 106, 106) 0.5px solid;
}
.art_title span {
  display: inline-block;
  margin-top: 10px;
  margin-right: 20px;
}
.blog-head-time {
  position: relative;
  display: flex;
  align-items: center;

  color: #ccf;
}
.blog-head-time-day {
  font-size: 40px;
  color: rgb(233, 177, 225);
  line-height: 1;
  margin-right: 3px;
}
.blog-head-time-date {
  display: flex;
  flex-direction: column;
}
.blog-head-time-date-month {
  font-size: 15px;
  text-transform: uppercase;
  word-break: keep-all;
}
.blog-head-time-date-year {
  line-height: 1.1;
  font-size: 14px;
}
.art_content {
  padding: 5px;
  display: flex;
  align-items: center;
}
.art_list {
  overflow: hidden;
  position: relative;
  transition: all 0.8s;
  padding: 20px;
  background: #fff;
  margin-bottom: 20px;
}
.art_content img {
  width: 200px;
  height: 160px;
  margin-right: 20px;
  border-radius: 5px;
}
.art_content span {
  height: 100%;
  margin-left: 10px;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}
.mycard {
  height: 400px;
  background: #fff;
  border-radius: 3px;
  position: relative;
}
.mycard section {
  margin: 25px;
}
.mycard_title {
  display: flex;
  height: 160px;
  align-items: center;
}
.my {
  margin-left: 10px;
}
.mycard_nickname {
  color: #55603d;
  text-transform: uppercase;
  /* font-style: italic; */
  font-weight: bold;
  font-size: 32px;
  letter-spacing: 0.2em;
}
.mycard_en {
  color: #55603d;
  text-transform: uppercase;
  font-weight: bold;
  font-size: 12px;
  letter-spacing: 0.2em;
}
.mycard .avatar {
  width: 70px;
  border: #f3f2f2 1px solid;
}
.avatar img {
  width: 70px;
}
.mycard i {
  display: block;
  /* margin: 20px 0; */
  height: 200px;
  border-radius: 3px;
  overflow: hidden;
}
.tagsclous {
  border-radius: 3px;
  background: #fff;
  padding: 5px 20px 0;
  margin: 20px 0;
  overflow: hidden;
}
h2.h_title {
  line-height: 50px;
  font-size: 22px;
}
.tagsclous ul {
  padding: 10px 0 20px 0;
  overflow: hidden;
  position: relative;
}
.tagsclous li:nth-child(3n-2) {
  background: #def6ff;
}
.tagsclous li:nth-child(3n-1) {
  background: #b0ecde;
}
.tagsclous li:nth-child(3n) {
  background: #f4dde6;
}
.tagsclous li {
  display: inline-block;
  line-height: 34px;
  text-align: center;
  position: relative;
  color: #2c3e50;
  margin: 4px 5px;
  padding: 0 14px;
  border-radius: 3px;
  transition: 0.2s;
}
.weather {
  transition: all 0.5s;
}
@media only screen and (max-width: 992px) {
  .banner-container {
    margin-top: 40vh;
    margin-left: 0;
    line-height: 1.5;
    color: rgb(251, 242, 242);
  }
  .swiper {
    height: 200px;
  }
  .cont_banner_box {
    overflow-x: auto;
    margin: 5px auto;
  }
  .con_banner {
    width: 960px;
  }
  .home-container {
    margin-top: 0;
  }
  .art_title {
    font-size: 12px;
  }
  .art_title h2 {
    width: 138px;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>